/*
 * JNISwingWrapper.cpp  0.4.0 / Nov 17, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#include "JNISwingWrapper.h"

// JNISwingWrapper :: Public Static Member Functions. --------------------------

/*!
 * \brief Checks for JNI exceptions.
 */
void JNISwingWrapper::checkException()
{
  Q_ASSERT(sm_env);
  JNIWrapper::checkException(sm_env);
}

/*!
 * \brief Test if an exception has occurred.
 *
 * \return \c true if the exception has occurred
 */
bool JNISwingWrapper::testException()
{
  Q_ASSERT(sm_env);
  return JNIWrapper::testException(sm_env);
}

/*!
 * \brief Prints the error message and terminates virtual machine.
 *        <p>
 *          NOTE: This method does not return.
 *        </p>
 *
 * \param errorMessage the error message
 */
void JNISwingWrapper::fatalError(const char *errorMessage)
{
  Q_ASSERT(sm_env);
  JNIWrapper::fatalError(sm_env, errorMessage); // does not return
}

/*!
 * \brief Throws java's internal error.
 *
 * \param errorMessage the error message
 */
void JNISwingWrapper::throwInternalError(const char *errorMessage)
{
  Q_ASSERT(sm_env);
  JNIWrapper::throwInternalError(sm_env, errorMessage);
}

/*!
 * \brief Throws java's out of memory error.
 *
 * \param errorMessage the error message
 */
void JNISwingWrapper::throwOutOfMemoryError(const char *errorMessage)
{
  Q_ASSERT(sm_env);
  JNIWrapper::throwOutOfMemoryError(sm_env, errorMessage);
}

/*!
 * \brief Throws java's runtime exception.
 *
 * \param exceptionMessage the exception message
 */
void JNISwingWrapper::throwRuntimeExcpetion(const char *exceptionMessage)
{
  Q_ASSERT(sm_env);
  JNIWrapper::throwRuntimeExcpetion(sm_env, exceptionMessage);
}

/*!
 * \brief Returns the fieldID for an instance field of a class.
 *
 * \param cls the class
 * \param name the field name
 * \param sig the field signature
 *
 * \return the fieldID for an instance field of a class
 */
jfieldID JNISwingWrapper::getFieldID(jclass cls, const char *name,
                                     const char *sig)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::getFieldID(sm_env, cls, name, sig);
}

/*!
 * \brief Returns the field ID for a static field of a class or interface.
 *
 * \param cls the class
 * \param name the field name
 * \param sig the field signature
 *
 * \return the field ID for a static field of a class or interface
 */
jfieldID JNISwingWrapper::getStaticFieldID(jclass cls, const char *name,
                                           const char *sig)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::getStaticFieldID(sm_env, cls, name, sig);
}

/*!
 * \brief Returns the methodID for an instance method of a class or interface.
 *
 * \param cls the class
 * \param name the method name
 * \param sig the method signature
 *
 * \return the methodID for an instance method of a class or interface
 */
jmethodID JNISwingWrapper::getMethodID(jclass cls, const char *name,
                                       const char *sig)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::getMethodID(sm_env, cls, name, sig);
}

/*!
 * \brief Returns the method ID for a static method of a class.
 *
 * \param cls the class
 * \param name the method name
 * \param sig the method signature
 *
 * \return the method ID for a static method of a class
 */
jmethodID JNISwingWrapper::getStaticMethodID(jclass cls, const char *name,
                                             const char *sig)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::getStaticMethodID(sm_env, cls, name, sig);
}

/*!
 * \brief Returns the value of the object field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 *
 * \return the value of the object field of the specified object
 */
jobject JNISwingWrapper::getObjectField(jobject obj, jfieldID fieldID)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::getObjectField(sm_env, obj, fieldID);
}

/*!
 * \brief Sets the value of the object field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 * \param val the new value
 */
void JNISwingWrapper::setObjectField(jobject obj, jfieldID fieldID,
                                     jobject val)
{
  Q_ASSERT(sm_env);
  JNIWrapper::setObjectField(sm_env, obj, fieldID, val);
}

/*!
 * \brief Returns the value of the boolean field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 *
 * \return the value of the boolean field of the specified object
 */
jboolean JNISwingWrapper::getBooleanField(jobject obj, jfieldID fieldID)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::getBooleanField(sm_env, obj, fieldID);
}

/*!
 * \brief Sets the value of the boolean field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 * \param val the new value
 */
void JNISwingWrapper::setBooleanField(jobject obj, jfieldID fieldID,
                                      jboolean val)
{
  Q_ASSERT(sm_env);
  JNIWrapper::setBooleanField(sm_env, obj, fieldID, val);
}

/*!
 * \brief Returns the value of the byte field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 *
 * \return the value of the byte field of the specified object
 */
jbyte JNISwingWrapper::getByteField(jobject obj, jfieldID fieldID)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::getByteField(sm_env, obj, fieldID);
}

/*!
 * \brief Sets the value of the byte field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 * \param val the new value
 */
void JNISwingWrapper::setByteField(jobject obj, jfieldID fieldID, jbyte val)
{
  Q_ASSERT(sm_env);
  JNIWrapper::setByteField(sm_env, obj, fieldID, val);
}

/*!
 * \brief Returns the value of the char field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 *
 * \return the value of the char field of the specified object
 */
jchar JNISwingWrapper::getCharField(jobject obj, jfieldID fieldID)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::getCharField(sm_env, obj, fieldID);
}

/*!
 * \brief Sets the value of the char field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 * \param val the new value
 */
void JNISwingWrapper::setCharField(jobject obj, jfieldID fieldID, jchar val)
{
  Q_ASSERT(sm_env);
  JNIWrapper::setCharField(sm_env, obj, fieldID, val);
}

/*!
 * \brief Returns the value of the short field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 *
 * \return the value of the short field of the specified object
 */
jshort JNISwingWrapper::getShortField(jobject obj, jfieldID fieldID)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::getShortField(sm_env, obj, fieldID);
}

/*!
 * \brief Sets the value of the short field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 * \param val the new value
 */
void JNISwingWrapper::setShortField(jobject obj, jfieldID fieldID, jshort val)
{
  Q_ASSERT(sm_env);
  JNIWrapper::setShortField(sm_env, obj, fieldID, val);
}

/*!
 * \brief Returns the value of the int field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 *
 * \return the value of the int field of the specified object
 */
jint JNISwingWrapper::getIntField(jobject obj, jfieldID fieldID)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::getIntField(sm_env, obj, fieldID);
}

/*!
 * \brief Sets the value of the int field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 * \param val the new value
 */
void JNISwingWrapper::setIntField(jobject obj, jfieldID fieldID, jint val)
{
  Q_ASSERT(sm_env);
  JNIWrapper::setIntField(sm_env, obj, fieldID, val);
}

/*!
 * \brief Returns the value of the long field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 *
 * \return the value of the long field of the specified object
 */
jlong JNISwingWrapper::getLongField(jobject obj, jfieldID fieldID)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::getLongField(sm_env, obj, fieldID);
}

/*!
 * \brief Sets the value of the long field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 * \param val the new value
 */
void JNISwingWrapper::setLongField(jobject obj, jfieldID fieldID, jlong val)
{
  Q_ASSERT(sm_env);
  JNIWrapper::setLongField(sm_env, obj, fieldID, val);
}

/*!
 * \brief Returns the value of the float field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 *
 * \return the value of the float field of the specified object
 */
jfloat JNISwingWrapper::getFloatField(jobject obj, jfieldID fieldID)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::getFloatField(sm_env, obj, fieldID);
}

/*!
 * \brief Sets the value of the float field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 * \param val the new value
 */
void JNISwingWrapper::setFloatField(jobject obj, jfieldID fieldID, jfloat val)
{
  Q_ASSERT(sm_env);
  JNIWrapper::setFloatField(sm_env, obj, fieldID, val);
}

/*!
 * \brief Returns the value of the double field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 *
 * \return the value of the double field of the specified object
 */
jdouble JNISwingWrapper::getDoubleField(jobject obj, jfieldID fieldID)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::getDoubleField(sm_env, obj, fieldID);
}

/*!
 * \brief Sets the value of the double field of the specified object.
 *
 * \param obj the object
 * \param fieldID the field ID
 * \param val the new value
 */
void JNISwingWrapper::setDoubleField(jobject obj, jfieldID fieldID,
                                     jdouble val)
{
  Q_ASSERT(sm_env);
  JNIWrapper::setDoubleField(sm_env, obj, fieldID, val);
}

/*!
 * \brief Calls JNI object method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param args the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callObjectMethod(jobject &result, jobject obj,
                                       jmethodID methodID, va_list &args)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::callObjectMethod(sm_env, result, obj, methodID, args);
}

/*!
 * \brief Calls JNI object method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param ... the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callObjectMethod(jobject &result, jobject obj,
                                       jmethodID methodID, ...)
{
  Q_ASSERT(sm_env);
  Q_ASSERT(methodID);
  va_list args;
  va_start(args, methodID);
  bool ret = JNIWrapper::callObjectMethod(sm_env, result, obj, methodID, args);
  va_end(args);
  return ret;
}

/*!
 * \brief Calls JNI boolean method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param args the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callBooleanMethod(jboolean &result, jobject obj,
                                        jmethodID methodID, va_list &args)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::callBooleanMethod(sm_env, result, obj, methodID, args);
}

/*!
 * \brief Calls JNI boolean method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param ... the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callBooleanMethod(jboolean &result, jobject obj,
                                        jmethodID methodID, ...)
{
  Q_ASSERT(sm_env);
  Q_ASSERT(methodID);
  va_list args;
  va_start(args, methodID);
  bool ret = JNIWrapper::callBooleanMethod(sm_env, result, obj, methodID, args);
  va_end(args);
  return ret;
}

/*!
 * \brief Calls JNI byte method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param args the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callByteMethod(jbyte &result, jobject obj,
                                     jmethodID methodID, va_list &args)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::callByteMethod(sm_env, result, obj, methodID, args);
}

/*!
 * \brief Calls JNI byte method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param ... the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callByteMethod(jbyte &result, jobject obj,
                                     jmethodID methodID, ...)
{
  Q_ASSERT(sm_env);
  Q_ASSERT(methodID);
  va_list args;
  va_start(args, methodID);
  bool ret = JNIWrapper::callByteMethod(sm_env, result, obj, methodID, args);
  va_end(args);
  return ret;
}

/*!
 * \brief Calls JNI char method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param args the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callCharMethod(jchar &result, jobject obj,
                                     jmethodID methodID, va_list &args)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::callCharMethod(sm_env, result, obj, methodID, args);
}

/*!
 * \brief Calls JNI char method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param ... the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callCharMethod(jchar &result, jobject obj,
                                     jmethodID methodID, ...)
{
  Q_ASSERT(sm_env);
  Q_ASSERT(methodID);
  va_list args;
  va_start(args, methodID);
  bool ret = JNIWrapper::callCharMethod(sm_env, result, obj, methodID, args);
  va_end(args);
  return ret;
}

/*!
 * \brief Calls JNI short method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param args the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callShortMethod(jshort &result, jobject obj,
                                      jmethodID methodID, va_list &args)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::callShortMethod(sm_env, result, obj, methodID, args);
}

/*!
 * \brief Calls JNI short method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param ... the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callShortMethod(jshort &result, jobject obj,
                                      jmethodID methodID, ...)
{
  Q_ASSERT(sm_env);
  Q_ASSERT(methodID);
  va_list args;
  va_start(args, methodID);
  bool ret = JNIWrapper::callShortMethod(sm_env, result, obj, methodID, args);
  va_end(args);
  return ret;
}

/*!
 * \brief Calls JNI int method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param args the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callIntMethod(jint &result, jobject obj,
                                    jmethodID methodID, va_list &args)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::callIntMethod(sm_env, result, obj, methodID, args);
}

/*!
 * \brief Calls JNI int method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param ... the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callIntMethod(jint &result, jobject obj,
                                    jmethodID methodID, ...)
{
  Q_ASSERT(sm_env);
  Q_ASSERT(methodID);
  va_list args;
  va_start(args, methodID);
  bool ret = JNIWrapper::callIntMethod(sm_env, result, obj, methodID, args);
  va_end(args);
  return ret;
}

/*!
 * \brief Calls JNI long method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param args the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callLongMethod(jlong &result, jobject obj,
                                     jmethodID methodID, va_list &args)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::callLongMethod(sm_env, result, obj, methodID, args);
}

/*!
 * \brief Calls JNI long method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param ... the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callLongMethod(jlong &result, jobject obj,
                                     jmethodID methodID, ...)
{
  Q_ASSERT(sm_env);
  Q_ASSERT(methodID);
  va_list args;
  va_start(args, methodID);
  bool ret = JNIWrapper::callLongMethod(sm_env, result, obj, methodID, args);
  va_end(args);
  return ret;
}

/*!
 * \brief Calls JNI float method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param args the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callFloatMethod(jfloat&result, jobject obj,
                                      jmethodID methodID, va_list &args)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::callFloatMethod(sm_env, result, obj, methodID, args);
}

/*!
 * \brief Calls JNI float method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param ... the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callFloatMethod(jfloat &result, jobject obj,
                                      jmethodID methodID, ...)
{
  Q_ASSERT(sm_env);
  Q_ASSERT(methodID);
  va_list args;
  va_start(args, methodID);
  bool ret = JNIWrapper::callFloatMethod(sm_env, result, obj, methodID, args);
  va_end(args);
  return ret;
}

/*!
 * \brief Calls JNI double method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param args the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callDoubleMethod(jdouble &result, jobject obj,
                                       jmethodID methodID, va_list &args)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::callDoubleMethod(sm_env, result, obj, methodID, args);
}

/*!
 * \brief Calls JNI double method.
 *
 * \param result the result
 * \param obj the jobject
 * \param methodID the method ID
 * \param ... the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callDoubleMethod(jdouble &result, jobject obj,
                                       jmethodID methodID, ...)
{
  Q_ASSERT(sm_env);
  Q_ASSERT(methodID);
  va_list args;
  va_start(args, methodID);
  bool ret = JNIWrapper::callDoubleMethod(sm_env, result, obj, methodID, args);
  va_end(args);
  return ret;
}

/*!
 * \brief Calls JNI void method.
 *
 * \param obj the java object
 * \param methodID the method ID
 * \param args the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callVoidMethod(jobject obj, jmethodID methodID,
                                     va_list &args)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::callVoidMethod(sm_env, obj, methodID, args);
}

/*!
 * \brief Calls JNI void method.
 *
 * \param obj the java object
 * \param methodID the method ID
 * \param ... the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callVoidMethod(jobject obj, jmethodID methodID, ...)
{
  Q_ASSERT(sm_env);
  Q_ASSERT(methodID);
  va_list args;
  va_start(args, methodID);
  bool ret = JNIWrapper::callVoidMethod(sm_env, obj, methodID, args);
  va_end(args);
  return ret;
}

/*!
 * \brief Returns jstring representation of the specified object.
 *
 * \param obj the object
 *
 * \return jstring representation of the specified object
 */
jstring JNISwingWrapper::toString(jobject obj)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::toString(sm_env, obj);
}

/*!
 * \brief Creates new Java string.
 *
 * \param uchars the unicode char array
 * \param len the length of the char array
 *
 * \return new Java string object
 */
jstring JNISwingWrapper::newString(const jchar *uchars, jsize len)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::newString(sm_env, uchars, len);
}

/*!
 * \brief Creates new Java string.
 *
 * \param bytes the UTF-8 char array
 *
 * \return new Java string object
 */
jstring JNISwingWrapper::newStringUTF(const char *bytes)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::newStringUTF(sm_env, bytes);
}

/*!
 * \brief Calls JNI static void method.
 *
 * \param cls the java class
 * \param methodID the method ID
 * \param args the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callStaticVoidMethod(jclass cls, jmethodID methodID,
                                           va_list &args)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::callStaticVoidMethod(sm_env, cls, methodID, args);
}

/*!
 * \brief Calls JNI static void method.
 *
 * \param cls the java class
 * \param methodID the method ID
 * \param ... the method arguments
 *
 * \return \c true if no exception is thrown
 */
bool JNISwingWrapper::callStaticVoidMethod(jclass cls, jmethodID methodID, ...)
{
  Q_ASSERT(sm_env);
  Q_ASSERT(methodID);
  va_list args;
  va_start(args, methodID);
  bool ret = JNIWrapper::callStaticVoidMethod(sm_env, cls, methodID, args);
  va_end(args);
  return ret;
}

/*!
 * \brief Creates and constructs new Java object.
 *
 * \param cls the object class
 * \param constructor the class constructor
 * \param args the constructor arguments
 *
 * \return new Java object
 */
jobject JNISwingWrapper::newObject(jclass cls, jmethodID constructor,
                                   va_list &args)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::newObject(sm_env, cls, constructor, args);
}

/*!
 * \brief Creates and constructs new Java object.
 *
 * \param cls the object class
 * \param constructor the class constructor
 * \param ... the constructor arguments
 *
 * \return new Java object
 */
jobject JNISwingWrapper::newObject(jclass cls, jmethodID constructor, ...)
{
  Q_ASSERT(sm_env);
  Q_ASSERT(constructor);
  va_list args;
  va_start(args, constructor);
  jobject ret = JNIWrapper::newObject(sm_env, cls, constructor, args);
  va_end(args);
  return ret;
}

/*!
 * \brief Creates new java object array.
 *
 * \param cls the class of the array elements
 * \param len the length of the array
 *
 * \return the java object array
 */
jobjectArray JNISwingWrapper::newObjectArray(jclass cls, jsize len)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::newObjectArray(sm_env, cls, len);
}

/*!
 * \brief Creates new java byte array.
 *
 * \param len the length of the array
 *
 * \return the java byte array
 */
jbyteArray JNISwingWrapper::newByteArray(jsize len)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::newByteArray(sm_env, len);
}

/*!
 * \brief Returns new Java global reference to the specified Java object.
 *
 * \param obj the Java object
 *
 * \return new Java global reference to the specified Java object
 */
jobject JNISwingWrapper::newGlobalRef(jobject obj)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::newGlobalRef(sm_env, obj);
}

/*!
 * \brief Returns new Java weak reference to the specified Java object.
 *
 * \param obj the Java object
 *
 * \return new Java weak reference to the specified Java object
 */
jweak JNISwingWrapper::newWeakGlobalRef(jobject obj)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::newWeakGlobalRef(sm_env, obj);
}

/*!
 * \brief Deletes the Java reference.
 *
 * \param objref the Java reference
 */
void JNISwingWrapper::deleteGlobalRef(jobject &objref)
{
  Q_ASSERT(sm_env);
  JNIWrapper::deleteGlobalRef(sm_env, objref);
}

/*!
 * \brief Deletes the Java weak reference.
 *
 * \param wobjref the Java weak reference
 */
void JNISwingWrapper::deleteWeakGlobalRef(jweak &wobjref)
{
  Q_ASSERT(sm_env);
  JNIWrapper::deleteWeakGlobalRef(sm_env, wobjref);
}

/*!
 * \brief Returns \c true if the specified weak reference is alive.
 *
 * \param wobjref the Java weak reference
 *
 * \return \c true if the specified weak reference is alive
 */
bool JNISwingWrapper::isLiveRef(jweak wobjref)
{
  Q_ASSERT(sm_env);
  return JNIWrapper::isLiveRef(sm_env, wobjref);
}

// JNISwingWrapper :: Private Static Member Function. -------------------------

void JNISwingWrapper::initialize(JNIEnv *env)
{
  Q_ASSERT(env);
  Q_ASSERT(!sm_env);
  sm_env = env;
}

// JNISwingWrapper :: Private Static Data Members. ----------------------------

JNIEnv *JNISwingWrapper::sm_env = 0;
bool JNISwingWrapper::sm_disposed = false;
